<?php
namespace api\app\controller;


use api\app\model\BannerModel;
use think\facade\Filesystem;

use api\app\validate\Vildate;

use cmf\controller\BaseController;
use think\facade\Db;

class BannerController extends BaseController
{


    public function index()
    {
        $list = BannerModel::select();
        return success('轮播图显示', $list);
    }



    public function addpost()
    {
        $image = request()->file('image');
        $result = Filesystem::disk('public')->putFile('image',$image);
        $image2 =   request()->domain().DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.$result;
        $data = input('post.');

        $validate = new Vildate();
        $result = $validate->scene('add')->check($data);
        if (!$result) {
            return error($validate->getError());
        }
        $data['image'] = $image2;
        if (BannerModel::create($data)) {
            return success('添加成功');
        } else {
            return error('添加失败');
        }
    }

    public function getBannerInfo()
    {
        $data = input('post.');
        $id = $data['id'];
        if (empty($id)) {
            return error('参数错误');
        }
        $news = BannerModel::find($id);
        if (!$news) {
            return error('账号不存在');
        }
        return success('返回成功',$news);
    }


}